import Vue from 'vue'
import VueRouter from 'vue-router'
// import HomeView from '../views/HomeView.vue'
import Login from '../views/Login.vue'

import CoreLogin from '../components/CoreLogin.vue'
import CoreRegister from '../components/CoreRegister.vue'



import Blog_Analysis from '../views/Blog_Analysis.vue'

import AnTimeRank from '../components/AnTimeRank.vue'
import AnCategory from '../components/AnCategory.vue'
import AnTitle from '../components/AnTitle.vue'
import AnTopic from '../components/AnTopic.vue'
import AnInteract from '../components/AnInteract.vue'
import AnInfluence from '../components/AnInfluence.vue'
import AnSomeone from '../components/AnSomeone.vue'
import AnLaborRank from '../components/AnLaborRank.vue'
// import Orders from '../components/Orders.vue'
// import ShopCar from '../components/ShopCar.vue'
// import Settings from '../components/Settings.vue'

Vue.use(VueRouter)

const routes = [
  {
    path: '',
    redirect:"/login"
  },
  {
    path: '/login',
    // name: 'Login',
    component: Login,
    children: [
      {
        path: '/',
        redirect:"coreLogin"
      },
      {
        path: 'coreLogin',
        component: CoreLogin
      },
      {
        path: 'coreRegister',
        component: CoreRegister
      }
    ]
  },
  {
    path:'/Blog_Analysis',
    // name: 'SportsShop',
    component:Blog_Analysis,
    children: [
      {
        path: '/',
        redirect:"AnSomeone"
      },
      {
        path: 'AnSomeone',
        component: AnSomeone
      },
      {
        path: 'AnTimeRank',
        component: AnTimeRank
      },
      {
        path: 'AnCategory',
        component: AnCategory
      },
      
      {
        path: 'AnTopic',
        component: AnTopic
      },
      {
        path: 'AnTitle',
        component: AnTitle
      },
      {
        path: 'AnLaborRank',
        component: AnLaborRank
      },
      {
        path: 'AnInteract',
        component: AnInteract
      },
      {
        path: 'AnInfluence',
        component: AnInfluence
      },
    ]
  }
]

const router = new VueRouter({
  routes
})

// 路由导航守卫
router.beforeEach((to, from, next) => {
  if (to.path === '/login') {
    return next()
  }
  if (to.path === '/login/coreLogin') {
    return next()
  }
  if (to.path === '/login/coreRegister') {
    return next()
  }

  const tokenStr = window.sessionStorage.getItem('user_id')
  if (!tokenStr) {
    return next('/login')
  }

  return next()

})

export default router
